package com.lovo.doudizhuPlus;

import com.lovo.util.Util;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PokerGui extends JFrame {
    public static ArrayList<Card> list = new ArrayList();
    public static List<Card> famer1 = new ArrayList();//农民
    public static List<Card> famer2 = new ArrayList();//农民
    public static List<Card> host = new ArrayList();//地主
    public static List<Card> base = new ArrayList();//底牌

    public static void main(String[] args) {
        init();
        xipai();
        fapai();
        sort();
        new PokerGui();
    }


    public PokerGui() {
        this.setLayout(null);
        int left = 500;
        for (int i = 0; i < 17; i++) {
            String str = famer1.get(i).getPoke();
            Icon IconImage = Util.getIcon(str);
            JLabel imgLable = new JLabel(IconImage);
            imgLable.setBounds(0, left, 105, 150);
            left -= 30;
            this.add(imgLable);
        }
        int bottom = 800;
        for (int i = 0; i < 17; i++) {
            String str = famer2.get(i).getPoke();
            Icon IconImage = Util.getIcon(str);
            JLabel imgLable = new JLabel(IconImage);
            imgLable.setBounds(bottom, 600, 105, 150);
            bottom -= 30;
            this.add(imgLable);
        }
        int right = 500;
        for (int i = 0; i < 17; i++) {
            String str = host.get(i).getPoke();
            Icon IconImage = Util.getIcon(str);
            JLabel imgLable = new JLabel(IconImage);
            imgLable.setBounds(1000, right, 105, 150);
            right -= 30;
            this.add(imgLable);
        }
        int center = 550;
        for (int i = 0; i < 3; i++) {
            String str = base.get(i).getPoke();
            Icon IconImage = Util.getIcon(str);
            JLabel imgLable = new JLabel(IconImage);
            imgLable.setBounds(center, 300, 105, 150);
            center -= 30;
            this.add(imgLable);
        }

        JButton btn1 = new JButton("洗牌");
        btn1.setBounds(350, 380, 100, 20);
        this.add(btn1);
        //设置窗口大小
        this.setSize(1200, 1200);

        //设置窗体标题
        this.setTitle("测试窗口");
        //设置窗口居中
        this.setLocationRelativeTo(null);
        //设置关闭窗口时结束程序
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //设置窗口可见
        this.setVisible(true);
    }

    //初始化
    public static void init() {
        String str = "";
        for (int i = 3; i < 16; i++) {
            for (int j = 1; j < 5; j++) {
                str = "/image/" + i + "_" + j + ".jpg";
                list.add(new Card(str, i));
            }
        }
        list.add(new Card("/image/16_1.jpg", 16));
        list.add(new Card("/image/17_1.jpg", 17));
    }

    public static void xipai() {
        Collections.shuffle(list);
        System.out.println(list);
    }

    public static void fapai() {
        famer1 = list.subList(0, 17);
        famer2 = list.subList(17, 34);
        host = list.subList(34, 51);
        base = list.subList(51, 54);

    }

    public static void sort() {
        famer1.sort(new MyComparetor());
        System.out.println(famer1);

        famer2.sort(new MyComparetor());
        System.out.println(famer2);

        host.sort(new MyComparetor());
        System.out.println(host);

        base.sort(new MyComparetor());
        System.out.println(base);
    }
}
